Added "delphi compatibility" unit to project GPSBabelGUI.
authoroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 6 Dec 2005 00:12:50 +0000 (00:12 +0000)
committeroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 6 Dec 2005 00:12:50 +0000 (00:12 +0000)
gpsbabel/win32/gui-2/delphi.pas [new file with mode: 0644]

diff --git a/gpsbabel/win32/gui-2/delphi.pas b/gpsbabel/win32/gui-2/delphi.pas
new file mode 100644 (file)
index 0000000..c9c5261
--- /dev/null
@@ -0,0 +1,93 @@
+unit delphi;\r
+\r
+// Delpi compatibility unit //\r
+\r
+interface\r
+\r
+uses\r
+  SysUtils, TypInfo;\r
+\r
+{$IFDEF VER120}\r
+function GetPropInfo(Instance: TObject; const PropertyName: string): PPropInfo; overload;\r
+function GetPropInfo(Instance: TObject; const Name: string; var PropInfo: TPropInfo): Boolean; overload;\r
+function GetObjectProp(Instance: TObject; Info: PPropInfo): TObject;\r
+function GetStrProp(Instance: TObject; const Name: string): string; overload;\r
+function GetStrProp(Instance: TObject; Info: PPropInfo): string; overload;\r
+procedure SetStrProp(Instance: TObject; const Name, Value: string); overload;\r
+procedure SetStrProp(Instance: TObject; Info: PPropInfo; const Value: string); overload;\r
+{$ENDIF}\r
+\r
+implementation\r
+\r
+{$IFDEF VER120}\r
+function GetPropInfo(Instance: TObject; const PropertyName: string): PPropInfo;\r
+begin\r
+  Result := TypInfo.GetPropInfo(Instance.ClassInfo, PropertyName);\r
+end;\r
+\r
+function GetObjectProp(Instance: TObject; Info: PPropInfo): TObject;\r
+begin\r
+  Result := Pointer(TypInfo.GetOrdProp(Instance, Info));\r
+end;\r
+\r
+function GetPropInfo(Instance: TObject; const Name: string; var PropInfo: TPropInfo): Boolean;\r
+var\r
+  Props: PPropList;\r
+  TypeData: PTypeData;\r
+  Info: PPropInfo;\r
+  i: Integer;\r
+begin\r
+  TypeData := GetTypeData(Instance.ClassInfo);\r
+  if ((TypeData <> nil) and (TypeData.PropCount > 0)) then\r
+  begin\r
+    GetMem(Props, TypeData.PropCount * SizeOf(Pointer));\r
+    try\r
+      GetPropInfos(Instance.ClassInfo, Props);\r
+      for i := 0 to TypeData.PropCount - 1 do\r
+      begin\r
+        Info := Props[i];\r
+        if (CompareText(Info.Name, Name) = 0) then\r
+        begin\r
+          PropInfo := Info^;\r
+          Result := True;\r
+          Exit;\r
+        end\r
+      end;\r
+    finally\r
+      FreeMem(Props);\r
+    end;\r
+  end;\r
+  Result := False;\r
+end;\r
+\r
+function GetStrProp(Instance: TObject; Info: PPropInfo): string;\r
+begin\r
+  Result := TypInfo.GetStrProp(Instance, Info);\r
+end;\r
+\r
+function GetStrProp(Instance: TObject; const Name: string): string;\r
+var\r
+  Info: TPropInfo;\r
+begin\r
+  if GetPropInfo(Instance, Name, Info) then\r
+    Result := TypInfo.GetStrProp(Instance, @Info)\r
+  else\r
+    Result := '';\r
+end;\r
+\r
+procedure SetStrProp(Instance: TObject; const Name, Value: string);\r
+var\r
+  Info: TPropInfo;\r
+begin\r
+  if GetPropInfo(Instance, Name, Info) then\r
+    SetStrProp(Instance, @Info, Value);\r
+end;\r
+\r
+procedure SetStrProp(Instance: TObject; Info: PPropInfo; const Value: string);\r
+begin\r
+  TypInfo.SetStrProp(Instance, Info, Value);\r
+end;\r
+\r
+{$ENDIF}\r
+\r
+end.\r